package org.huang.spock.spring

import org.huang.spock.spring.component.LockManage
import org.huang.spock.spring.service.LockService
import spock.lang.IgnoreIf
import spock.lang.Specification

import java.util.concurrent.locks.Lock

class LockServiceTest extends Specification {

    def lockManage = Mock(LockManage)
    def lockService = new LockService(lockManage: lockManage)

    /**
     * case:返回一个mock对象，这个mock对象继续mock 部分方法
     */
    @IgnoreIf({System.getProperty("os.name").contains("windows")})
    def "test testLockMock"() {
        given:
        lockManage.getLock(_) >> Mock(Lock).with {
            it.tryLock() >> locked
            it
        }
        expect:
        lockService.testLockMock("aaa") == result
        where:
        locked || result
        true   || 'Success'
        false  || 'Error'
    }

}
